<template>
  <el-dialog :title="'日志'" :close-on-click-modal="false" :visible.sync="visible">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item label="创建日期">
        <el-date-picker @change="getDataList()" v-model="dataForm.date" type="datetimerange" start-placeholder="开始日期" end-placeholder="结束日期" value-format="yyyy-MM-dd HH:mm" :default-time="['00:00:00', '23:59:59']"></el-date-picker>
      </el-form-item>
    </el-form>
    <el-table :data="dataList" border v-loading="dataListLoading" style="width: 100%;" :default-expand-all="true">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">
            <el-form-item>
              <span>{{ props.row.floorRoomDesc }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>
      <el-table-column prop="sellerName" header-align="center" align="center" label="商家"></el-table-column>
      <el-table-column prop="userId" header-align="center" align="center" label="操作人"></el-table-column>
      <el-table-column prop="createTime" header-align="center" align="center" label="创建时间"></el-table-column>
<!--      <el-table-column fixed="right" header-align="center" align="center" width="150" label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column> -->
    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper"
    ></el-pagination>
  </el-dialog>
</template>

<script>
import moment from 'moment';
export default {
  data() {
    return {
      item: {},
      visible: false,
      dataForm: {
        date:[moment().format('YYYY-MM-DD'),moment().add(1, 'days').format('YYYY-MM-DD')],
        floorRoomId:'',
        startdate:'',
        stopdate:'',
      },
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListLoading: false,
      dataListSelections: []
    };
  },
  methods: {
    init(item) {
      this.item = item;
      this.visible = true;
      this.dataForm.floorRoomId = item.id
      this.$nextTick(() => {
        this.dataForm.date = [moment().format('YYYY-MM-DD'),moment().add(1, 'days').format('YYYY-MM-DD')]
        this.getDataList();
      });
    },
    // 获取数据列表
    getDataList() {
      this.dataListLoading = true;
      if(this.dataForm.date.length != 0){
        this.dataForm.startdate = this.dataForm.date[0]
        this.dataForm.stopdate = this.dataForm.date[1]
      }
      this.$http({
        url: this.$http.adornUrl('/hotel/thotelfloorroomlog/list'),
        method: 'get',
        params: this.$http.adornParams({
          page: this.pageIndex,
          limit: this.pageSize,
          startdate: this.dataForm.startdate,
          stopdate: this.dataForm.stopdate,
          floorRoomId: this.dataForm.floorRoomId,
        })
      }).then(({ data }) => {
        if (data && data.code === 0) {
          this.dataList = data.page.list;
          this.totalPage = data.page.totalCount;
        } else {
          this.dataList = [];
          this.totalPage = 0;
        }
        this.dataListLoading = false;
      });
    },
    // 每页数
    sizeChangeHandle(val) {
      this.pageSize = val;
      this.pageIndex = 1;
      this.getDataList();
    },
    // 当前页
    currentChangeHandle(val) {
      this.pageIndex = val;
      this.getDataList();
    }
  }
};
</script>
